package ls.jpa.chapter2.service;

import ls.jpa.chapter2.dao.UserDao;
import ls.jpa.chapter2.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author Barudisshu
 */
@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    @Transactional
    public UserInfo create(String name,String password,Integer age){

        UserInfo userInfo = new UserInfo();
        userInfo.setUsername(name);
        userInfo.setPassword(password);
        userInfo.setAge(age);

        return userDao.save(userInfo);
    }

    public List<UserInfo> getAll(){

        return userDao.getAll();
    }
}
